package com.hwl.lab.service;

import com.hwl.lab.entity.Area;
import com.hwl.lab.entity.Role;
import com.hwl.lab.repository.AreaRepository;
import com.hwl.lab.repository.RoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AreaService {
    @Autowired
    private AreaRepository areaRepository;
    //分页实现
    public Page<Area> findAll( Integer page, Integer size){
        Pageable pageable=  PageRequest.of(page-1,size);
        return areaRepository.findAll(pageable);
    }
    //不分页
    public List<Area> findAll() {
        return areaRepository.findAll();
    }
    //通过账号查询
    public Area findByAreaid(String areaid){
        return areaRepository.findByAreaid(areaid);
    }
    //保存，修改
    public Area saveArea(Area area){
       return  areaRepository.save(area);
    }
    //通过账号删除
    public void deleteById(Long id){
        areaRepository.deleteById(id);
    }
}
